Backtracking, Interleaving, and Terminating Monad Transformers
نویسندگان
چکیده
We design and implement a library for adding backtracking computations to any Haskell monad. Inspired by logic programming, our library provides, in addition to the operations required by the MonadPlus interface, constructs for fair disjunctions, fair conjunctions, conditionals, pruning, and an expressive top-level interface. Implementing these additional constructs is easy in models of backtracking based on streams, but not known to be possible in continuation-based models. We show that all these additional constructs can be generically and monadically realized using a single primitive msplit. We present two implementations of the library: one using success and failure continuations; and the other using control operators for manipulating delimited continuations.
منابع مشابه
Eilenberg-Moore Monoids and Backtracking Monad Transformers
We develop an algebraic underpinning of backtracking monad transformers in the general setting of monoidal categories. As our main technical device, we introduce Eilenberg–Moore monoids, which combine monoids with algebras for strong monads. We show that Eilenberg–Moore monoids coincide with algebras for the list monad transformer (‘done right’) known from Haskell libraries. From this, we obtai...
متن کاملMonad Transformers for Backtracking Search
This paper extends Escardó and Oliva’s selection monad to the selection monad transformer, a general monadic framework for expressing backtracking search algorithms in Haskell. The use of the closely related continuation monad transformer for similar purposes is also discussed, including an implementation of a DPLL-like SAT solver with no explicit recursion. Continuing a line of work exploring ...
متن کاملDeriving Backtracking Monad Transformers Functional Pearl
In a paper about pretty printing J. Hughes introdu ed two fundamental te hniques for deriving programs from their spe i ation, where a spe i ation onsists of a signature and properties that the operations of the signature are required to satisfy. Brie y, the rst te hnique, the term implementation, represents the operations by terms and works by de ning a mapping from operations to observations ...
متن کاملPrological Features in a Functional Setting Axioms and Implementation
The purpose of this paper is twofold. First, we show that Prological features can be smoothly integrated into a functional language like Haskell. The resultingìanguage', embedded Prolog, lacks some concepts such as logical variables but it inherits all of Haskell's strengths eg static polymorphic typing, higher order functions etc. Technically, the integration is achieved using monads and monad...
متن کاملTracing monadic computations and representing effects
In functional programming, monads are supposed to encapsulate computations, effectfully producing the final result, but keeping to themselves the means of acquiring it. For various reasons, we sometimes want to reveal the internals of a computation. To make that possible, in this paper we introduce monad transformers that add the ability to automatically accumulate observations about the course...
متن کامل